package com.snake.springboot.custom.controller.base;

import com.snake.springboot.custom.api.model.base.CustPointsFreezeModel;
import com.snake.springboot.custom.api.model.base.CustPointsModel;
import com.snake.springboot.custom.api.model.points.PointsChangeModel;
import com.snake.springboot.custom.api.service.base.CustPointsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>商户算力信息
 * 类{@code CustPoints} </br>
 * 创建时间2025/2/21 17:42
 *
 * @author yangxt
 * @see
 */
@Api(tags = "商户管理-商户算力信息")
@RestController
@RequestMapping("/cust/points")
public class CustPointsController {

    private CustPointsService pointsService;
    @Autowired
    public CustPointsController(CustPointsService pointsService) {
        this.pointsService = pointsService;
    }

    @ApiOperation("算力增加")
    @PostMapping("/add")
    public ResponseResult<CustPointsModel> add(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) PointsChangeModel model) {
        pointsService.add(model);
        return ResponseResultFactory.ucc("算力增加成功！");
    }

    @ApiOperation("算力扣减")
    @PostMapping("/reduce")
    public ResponseResult<CustPointsModel> reduce(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody PointsChangeModel model) {
        pointsService.reduce(model);
        return ResponseResultFactory.ucc("算力扣减成功！");
    }


    @ApiOperation("冻结")
    @PostMapping("/freeze")
    public ResponseResult<CustPointsModel> freeze(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustPointsFreezeModel model) {
        pointsService.freeze(model);
        return ResponseResultFactory.ucc("算力冻结成功！");
    }

    @ApiOperation("解冻")
    @PostMapping("/thaw")
    public ResponseResult<CustPointsModel> thaw(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustPointsFreezeModel model) {
        pointsService.thaw(model);
        return ResponseResultFactory.ucc("算力冻结成功！");
    }

    @ApiOperation("抵扣算力成功")
    @PostMapping("/reduceFreeze")
    public ResponseResult<CustPointsModel> reduceFreeze(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustPointsFreezeModel model) {
        pointsService.reduceFreeze(model);
        return ResponseResultFactory.ucc("算力冻结成功！");
    }

    @ApiOperation("查询详情")
    @GetMapping("/detail/{customId}")
    public ResponseResult<CustPointsModel> queryById(@PathVariable("customId") String customId) {
        CustPointsModel pointsModel = pointsService.queryById(customId);
        return ResponseResultFactory.ucc("查询详情！",pointsModel);
    }

    @ApiOperation("内部-算力扣减")
    @PostMapping("/inner-reduce")
    public ResponseResult<CustPointsModel> innerReduce(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody PointsChangeModel model) {
        pointsService.reduce(model);
        return ResponseResultFactory.ucc("算力扣减成功！");
    }
}
